<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="设备名称" prop="sedDeviceName">
        <el-input
          v-model="queryParams.sedDeviceName"
          placeholder="请输入设备名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="设备IP" prop="sedDeviceIp">
        <el-input
          v-model="queryParams.sedDeviceIp"
          placeholder="请输入设备IP"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="设备MAC" prop="sedDeviceMac">
        <el-input
          v-model="queryParams.sedDeviceMac"
          placeholder="请输入设备MAC"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="硬盘序列号" prop="sedDiskSerial">
        <el-input
          v-model="queryParams.sedDiskSerial"
          placeholder="请输入硬盘序列号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="设备来源" prop="sedDeviceOrigin">
        <el-input
          v-model="queryParams.sedDeviceOrigin"
          placeholder="请输入设备来源"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="设备使用者" prop="sedDeviceUser">
        <el-input
          v-model="queryParams.sedDeviceUser"
          placeholder="请输入设备使用者"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="检测创建时间" prop="sedCreateTime">
        <el-date-picker clearable
          v-model="queryParams.sedCreateTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择检测创建时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="检测删除时间" prop="sedDeleteTime">
        <el-date-picker clearable
          v-model="queryParams.sedDeleteTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择检测删除时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="检测修改时间" prop="sedUpdateTime">
        <el-date-picker clearable
          v-model="queryParams.sedUpdateTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择检测修改时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="检测提交用户" prop="sedCommitUser">
        <el-date-picker clearable
          v-model="queryParams.sedCommitUser"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择检测提交用户">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="冗余字段1" prop="sedBackup1">
        <el-input
          v-model="queryParams.sedBackup1"
          placeholder="请输入冗余字段1"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="冗余字段2" prop="sedBackup2">
        <el-input
          v-model="queryParams.sedBackup2"
          placeholder="请输入冗余字段2"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="冗余字段3" prop="sedBackup3">
        <el-input
          v-model="queryParams.sedBackup3"
          placeholder="请输入冗余字段3"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:detection:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:detection:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:detection:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:detection:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="detectionList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="系统环境检测数据编码" align="center" prop="sedCode" />
      <el-table-column label="检测类型:如：终端用户/系统设备" align="center" prop="sedType" />
      <el-table-column label="设备名称" align="center" prop="sedDeviceName" />
      <el-table-column label="设备IP" align="center" prop="sedDeviceIp" />
      <el-table-column label="设备MAC" align="center" prop="sedDeviceMac" />
      <el-table-column label="硬盘序列号" align="center" prop="sedDiskSerial" />
      <el-table-column label="设备来源" align="center" prop="sedDeviceOrigin" />
      <el-table-column label="设备使用者" align="center" prop="sedDeviceUser" />
      <el-table-column label="检测创建时间" align="center" prop="sedCreateTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.sedCreateTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="检测删除时间" align="center" prop="sedDeleteTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.sedDeleteTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="检测修改时间" align="center" prop="sedUpdateTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.sedUpdateTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="检测提交用户" align="center" prop="sedCommitUser" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.sedCommitUser, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="检测状态：0：未提交检测1：提交检测2：预审通过" align="center" prop="sedDetectionStatus" />
      <el-table-column label="删除状态码：0：删除1：未删除" align="center" prop="sedDeleteStatus" />
      <el-table-column label="冗余字段1" align="center" prop="sedBackup1" />
      <el-table-column label="冗余字段2" align="center" prop="sedBackup2" />
      <el-table-column label="冗余字段3" align="center" prop="sedBackup3" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:detection:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:detection:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改系统环境检测对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="设备名称" prop="sedDeviceName">
          <el-input v-model="form.sedDeviceName" placeholder="请输入设备名称" />
        </el-form-item>
        <el-form-item label="设备IP" prop="sedDeviceIp">
          <el-input v-model="form.sedDeviceIp" placeholder="请输入设备IP" />
        </el-form-item>
        <el-form-item label="设备MAC" prop="sedDeviceMac">
          <el-input v-model="form.sedDeviceMac" placeholder="请输入设备MAC" />
        </el-form-item>
        <el-form-item label="硬盘序列号" prop="sedDiskSerial">
          <el-input v-model="form.sedDiskSerial" placeholder="请输入硬盘序列号" />
        </el-form-item>
        <el-form-item label="设备来源" prop="sedDeviceOrigin">
          <el-input v-model="form.sedDeviceOrigin" placeholder="请输入设备来源" />
        </el-form-item>
        <el-form-item label="设备使用者" prop="sedDeviceUser">
          <el-input v-model="form.sedDeviceUser" placeholder="请输入设备使用者" />
        </el-form-item>
        <el-form-item label="检测创建时间" prop="sedCreateTime">
          <el-date-picker clearable
            v-model="form.sedCreateTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择检测创建时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="检测删除时间" prop="sedDeleteTime">
          <el-date-picker clearable
            v-model="form.sedDeleteTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择检测删除时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="检测修改时间" prop="sedUpdateTime">
          <el-date-picker clearable
            v-model="form.sedUpdateTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择检测修改时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="检测提交用户" prop="sedCommitUser">
          <el-date-picker clearable
            v-model="form.sedCommitUser"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择检测提交用户">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="冗余字段1" prop="sedBackup1">
          <el-input v-model="form.sedBackup1" placeholder="请输入冗余字段1" />
        </el-form-item>
        <el-form-item label="冗余字段2" prop="sedBackup2">
          <el-input v-model="form.sedBackup2" placeholder="请输入冗余字段2" />
        </el-form-item>
        <el-form-item label="冗余字段3" prop="sedBackup3">
          <el-input v-model="form.sedBackup3" placeholder="请输入冗余字段3" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listDetection, getDetection, delDetection, addDetection, updateDetection } from "@/api/system/detection";

export default {
  name: "Detection",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 系统环境检测表格数据
      detectionList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        sedType: null,
        sedDeviceName: null,
        sedDeviceIp: null,
        sedDeviceMac: null,
        sedDiskSerial: null,
        sedDeviceOrigin: null,
        sedDeviceUser: null,
        sedCreateTime: null,
        sedDeleteTime: null,
        sedUpdateTime: null,
        sedCommitUser: null,
        sedDetectionStatus: null,
        sedDeleteStatus: null,
        sedBackup1: null,
        sedBackup2: null,
        sedBackup3: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询系统环境检测列表 */
    getList() {
      this.loading = true;
      listDetection(this.queryParams).then(response => {
        this.detectionList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        sedCode: null,
        sedType: null,
        sedDeviceName: null,
        sedDeviceIp: null,
        sedDeviceMac: null,
        sedDiskSerial: null,
        sedDeviceOrigin: null,
        sedDeviceUser: null,
        sedCreateTime: null,
        sedDeleteTime: null,
        sedUpdateTime: null,
        sedCommitUser: null,
        sedDetectionStatus: null,
        sedDeleteStatus: null,
        sedBackup1: null,
        sedBackup2: null,
        sedBackup3: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.sedCode)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加系统环境检测";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const sedCode = row.sedCode || this.ids
      getDetection(sedCode).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改系统环境检测";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.sedCode != null) {
            updateDetection(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addDetection(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const sedCodes = row.sedCode || this.ids;
      this.$modal.confirm('是否确认删除系统环境检测编号为"' + sedCodes + '"的数据项？').then(function() {
        return delDetection(sedCodes);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/detection/export', {
        ...this.queryParams
      }, `detection_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
